<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    <head>
        <title>美业红</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1">
        <link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
        <link href="/public/css/main.css" rel="stylesheet">
        <script type='text/javascript' src='/public/js/jquery-3.1.1.min.js'></script>
        <script type="text/javascript" src='/public/js/jquery.validate.js'></script>
        <script type="text/javascript" src='/public/js/main/main.js'></script>
        <script>
            var _hmt = _hmt || [];
            (function () {
                var hm = document.createElement("script");
                hm.src = "//hm.baidu.com/hm.js?8d43b5b5d798921b66d689f7a792e6e2";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
        </script>
        <script type="text/javascript">
            document.domain = '<?php echo _DOMAIN_ALL_;?>';
        </script>
        <link rel="shortcut icon" type="image/ico" href="/favicon.ico">
    </head>
    <body style="background-color: #f4f4f4;">
        <div class="navigation">
            <div class='navlogo'>
            <a href='/'><img class='_navlogo' src="/public/images/logo.png"></a>
            </div>
            <div class='navson'>
                <ul class='fr'>
                <li><a href='/' class='anchor'><b>主页</b></a></li>
                <li><a href="/home/store" class='anchor'><b>店铺</b></a></li>
                <li><a href="/home/barber" class='anchor'><b>成员</b></a></li>
                <li><a href="/home/action" class='anchor'><b>活动</b></a></li>
                <li><a href="/home/order" class='anchor'><b>订单</b></a></li>
                <li><a href="/home/coupon" class='anchor'><b>优惠券</b></a></li>
                <li><a href="/home/goods" class='anchor'><b>商品</b></a></li>
                </ul>
           </div>
            <?php if($_SESSION['id']>0){?>
            <div style="float:right;padding-right:10%">你好:<span id='login_name'></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='anchor' href='/home/passport/repassword'>修改密码</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='anchor' href='/home/passport/logout'>退出</a></div>
            <?php }?>
        </div>
        <div style='margin-top:80px;width:100%'>
            <img class='_navlogo' src="/public/images/contentlogo.png" style='width:100%;height:100px'>
        </div>
        <div class='container'>
            <div class='_main'>
            <div class='_line'></div> 
<div class="_contro">
    <select id="store">
        <option value='0'>全部店铺</option>
        <?php foreach($store as $v){?>
        <option value='<?php echo $v['id'];?>' <?php if($store_id==$v['id']){echo "selected='selected'";}?>><?php echo $v['name'];?></option>
        <?php }?>
    </select>&nbsp;&nbsp;&nbsp;&nbsp;
    <select name="type" id="type">
        <option <?php if($type == 0){echo 'selected="selected"';}?> value="0">全部状态</option>
        <option <?php if($type == 1){echo 'selected="selected"';}?> value="1">已发布</option>
        <option <?php if($type == 2){echo 'selected="selected"';}?> value="2">草稿</option>
    </select>&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="/home/action/create" class="_a"><font class="_font"><b>+</b>创建新活动</font></a>
</div>
<div class='_cut'></div>
<div id='content'>
    <?php foreach($actions as $k=>$v){ ?>
    <?php if($k%3==0){ ?>
    <div class='row'>
        <?php }?>
        <div class='col-sm-3 col-md-4 full'>
            <div class='thumbnail' style="margin-bottom:10px">
                <div style="height:12rem;overflow: hidden">
                    <a target="_blank" href='/home/action/info?id=<?php echo ($v["id"]); ?>'>
                        <?php if(!empty($v['img'])){ ?>
                        <img class='_img' src="<?php echo 'http://'.IMAGE_DOMAIN_.$v['img'][0]; ?>" style='width:49.5%;height:12rem;float:left;'/>
                        <img class='_img' src="<?php echo 'http://'.IMAGE_DOMAIN_.$v['img'][1]; ?>" style='width:49.5%;height:12rem;float:right;'/>
                        <?php  }else{ ?>
                        <img class='_img' src="<?php echo 'http://'.IMAGE_DOMAIN_.'/upload/action.jpg'; ?>" style='width:49.5%;height:12rem;float:left;'/>
                        <img class='_img' src="<?php echo 'http://'.IMAGE_DOMAIN_.'/upload/action.jpg'; ?>" style='width:49.5%;height:12rem;float:right;'/>   
                        <?php } ?>
                    </a>
                </div>
            </div>
            <div class='caption' style='overflow: hidden'>
                <div  class='_hidden' ><a class='_a' href='/home/action/info?id=<?php echo ($v["id"]); ?>'><?php echo ($v["action_name"]); ?></a></div>
                <div>
                    <span style="margin-left: 6px">参加人数：<?php echo $v['num'];?></span>
                    <span style="margin-left: 6px">活动状态：<?php echo $v['status_name'];?></span>
                <div style="float:right;">
                    <?php if($v['status']!=2 && $v['model_type']!=2){ ?>
                    <span ><a href="/home/analyze?id=<?php echo $v['id'];?>">数据统计</a></span>
                    <span ><a href="/home/order?id=<?php echo $v['id'];?>">订单</a></span>
                    <?php }?>
                    <span ><a href="javascript:;" onclick="Delete(<?php echo $v['id'];?>,<?php echo $v['num'];?>,<?php echo $v['status'];?>,<?php echo $v['store_id'];?>,<?php echo $v['end_time'];?>,<?php echo $v['use_end_time'];?>)" >删除</a></span>
                 </div>   
                </div>
            </div>
        </div>
        <?php if(($k+1)%3==0 || $actions[$k+1]['id']<1){ ?>
    </div>
    <?php } ?>
    <?php } ?>
</div>
<div class="clear"></div>
<script type='text/javascript'>
    $(document).ready(function () {
        var number = 12;
        function loaddata()
        {
            if (number == -1) {
                return;
            }
            totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());
            if ($(document).height() <= totalheight)
            {
               $('#loadinggif').show();
                var type = $("#type").val();
                var store_id = $("#store").val();
                $.ajax({url: "/home/action/append?start=" + number +"&store_id="+store_id+ "&type=" + type, async: true, success: function (msg) {
                        if (msg == 'false') {
                            number = -1;
                            return;
                        }
                        var html = "";
                        msg = eval('(' + msg + ')');
                        $.each(msg, function (i, v) {
                            if (i % 3 == 0) {
                                html += "<div class='row'>";
                            }
                            html += "<div class='col-sm-3 col-md-4 full'>";
                            html += "<div class='thumbnail' style='margin-bottom:10px'>";
                            html += "<div style='height:12rem;overflow: hidden'>";
                            html += "<a target='_blank' href='/home/action/info?id=";
                            html += v.id;
                            html += "'>";
                            if(v.img){ 
                                html += "<img class='_img' src='";
                                html += "<?php echo 'http://'.IMAGE_DOMAIN_; ?>";
                                html += v.img[0];
                                html += "' style='width:49.5%;float:left;height:12rem;'/>";
                                html += "<img class='_img' src='";
                                html += "<?php echo 'http://'.IMAGE_DOMAIN_; ?>";
                                html += v.img[1];
                                html += "' style='width:49.5%;float:right;height:12rem;'/>";
                            }else{
                                var img = "<?php echo 'http://'.IMAGE_DOMAIN_.'/upload/action.jpg'; ?>";
                                html += "<img class='_img' src='";
                                html += img;
                                html += "' style='width:49.5%;float:left;height:12rem;'/>";
                                html += "<img class='_img' src='";
                                html += img;
                                html += "' style='width:49.5%;float:right;height:12rem;'/>";
                            }
                            html += "</a></div></div><div class='caption'><span style='margin-left: 6px'><a class='_a' href='/home/action/info?id=";
                            html += v.id;
                            html += "'>";
                            html += v.action_name;
                            html += "</a></span>";
                            html += '<div><span style="margin-left: 6px">参加人数：';
                            html += v.num;
                            html += '</span><span style="margin-left: 6px">活动状态：';
                            html += v.status_name;
                            html += '<div style="float:right;">';
                            if (v.status != 2 && v.model_type != 2) {
                                html += '</span><span style="margin-left: 6px"><a href="/home/analyze?id=' + v.id + '">数据统计</a>';
                                html += '<span style="margin-left: 6px"><a href="/home/order?id='+v.id+'">订单</a></span>';
                            }
                            html += '<span style="margin-left: 6px "><a href="javascript:;" onclick="Delete(';
                            html += v.id+','+v.num+','+v.status+','+v.store_id+','+v.end_time+','+v.use_end_time;
                            html +=  ')" >删除</a></span>';
                            html += "</div></div></div></div>";
                            if ((i + 1) % 3 == 0) {
                                html += "</div>";
                            }
                            number += 1;
                        });
                        $('#content').append(html);
                        $('#loadinggif').hide();
                    }});
            }
            $('#loadinggif').hide();
        }

        $(window).scroll(function () {
            loaddata();
        });
        $("#store").change(function () {
            var store_id = $("#store").val();
            var type = $("#type").val();
            setTimeout(window.location.href = '/home/action?store_id=' + store_id + '&type=' + type);
        });
        $("#type").change(function () {
            var store_id = $("#store").val();
            var type = $("#type").val();
            setTimeout(window.location.href = '/home/action?store_id=' + store_id + '&type=' + type);
        }); 
    });

    function Delete(id,num,status,store_id,end_time,use_end_time){
        var time = Date.parse(new Date())/1000;

        if(confirm("确认删除该活动？")){
            if(use_end_time>time && num>0 ){
                alert("该活动未到使用截止时间，不可删除！");
                return;
            }
            if(status==1 && end_time>time ){
                if(confirm('该活动还在进行中，确认要删除？')){
                    if(num>0){
                       alert("该活动已经有人参加，不可删除！");
                        return; 
                    }
                }else{
                    return;
                }    
            }
            $.ajax({
                url: "/home/action/deleteAction?id="+id+"&status="+status+"&store_id="+store_id, async:true, success: function (msg) {
                    if(msg=='1'){
                        alert("删除成功！");
                        window.location.reload();
                    }else{
                        alert("删除失败！");
                        return; 
                    }
                } 
            }); 
        }else{
            return;
        }
    }

    
</script>
<div style="width:100%;text-align: center;display:none" id="loadinggif">
    <img src="/public/images/loading.gif" style="width:70px;height: 70px">
</div>
</div>
</div>
<div class='_line'></div>
<div class="newfooter">
    ©2015-2017 All Rights Reserved ( 京ICP备15010043号 ) 
</div>
<div id='mask_layer' style="text-align: center;width:100%;height:100%;overflow:hidden;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#8E8E8E',endColorstr='##8E8E8E');
     background-color:rgba(255, 255, 255, 0.4);position:fixed; _position:absolute; top:0;left:0; z-index:5000;display:none ">
    <div style="padding-top: 20%"><h1><b>loading<span id="_loading"></span></b></h1></div>
</div>
</body>
<script type="text/javascript" src='/public/js/top.js'></script>
</html>